
new Vue({
    el: '#app',
    delimiters:['[[', ']]'],

    data: {
        categories: [],
    },

    methods: {
        /**
         * 请求礼物分类列表
         */
        requestGiftCategoryList() {
            let url = "{% url 'gma:api_get_gift_category_list' %}";
            new my_ajax(url, {}, '', '', (data) => {
                console.table(data);
                this.categories = data;

                this.categories.forEach(category => {
                    category.edit_url = `/gma/config/gift_category/${category.category_id}/edit/`;
                });
            });
        },


        /**
         * 点击礼物分类
         * @param category
         */
        clickGiftCategory(category) {
            if (category.enabled === 1) {
                this.disableGiftCategory(category.id);
            } else {
                this.enableGiftCategory(category.id);
            }
        },

        /**
         * 启用礼物分类
         *
         * @param gift_category_id
         */
        enableGiftCategory(gift_category_id) {
            let data = {
                'gift_category_id': gift_category_id,
            };

            let url = "{% url 'gma:api_enable_gift_category' %}";
            new my_ajax(url, data, '', '', () => {
                show_toast('成功开启');
                this.requestGiftCategoryList();
            });
        },

        /**
         * 禁用礼物分类
         * @param gift_category_id
         */
        disableGiftCategory(gift_category_id) {
            let data = {
                'gift_category_id': gift_category_id,
            };

            let url = "{% url 'gma:api_disable_gift_category' %}";
            new my_ajax(url, data, '', '', () => {
                show_toast('成功关闭');
                this.requestGiftCategoryList();
            });
        },
    },

    mounted() {
        this.requestGiftCategoryList();
    },
});
